package com.example.ssmlab2.listener;


import com.mysql.jdbc.AbandonedConnectionCleanupThread;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.util.Enumeration;

/**
 * ClassName:DriverListener
 * Package:com.example.ssmblogs.listener
 * Description:
 *
 * @Author:ZhangXin
 * @Create:2023/3/27-16:01
 * @Version:v1.0
 */
@WebListener
public class DriverListener implements ServletContextListener {
    @Override
    public void contextDestroyed(ServletContextEvent sce){
        Enumeration<Driver> drivers = DriverManager.getDrivers();

        while (drivers.hasMoreElements()){
            Driver driver = drivers.nextElement();

            try {
                DriverManager.deregisterDriver(driver);
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }
        AbandonedConnectionCleanupThread.checkedShutdown();
    }

}
